/**
 * Created by yuzhou on 16/9/19.
 */

define([
    'vue','debug', 'text!tpl/userDetail.html',
    'vuex/actions/user',
    'mixin/userMixin'
], function(Vue, Debug, userDetailHtml, userAction, userMixin) {

    return Vue.extend({
        template: userDetailHtml,
        data: function(){
            return {
                fromUrl: '/user'
            }
        },
        vuex:{
            getters: {
                user: function(store){
                    return store.user.currentUser
                },
                userIndex: function(store) {
                    return store.user.currentUserIndex
                },
                userSize: function(store) {
                    return store.user.page.list.length
                },
                prevUserItem: function(store){
                    if(store.user.currentUserIndex > 0) {
                        return store.user.page.list[store.user.currentUserIndex - 1]
                    }
                    return null
                },
                nextUserItem: function(store){
                    if(store.user.currentUserIndex != -1
                        && store.user.currentUserIndex < store.user.page.list.length -1) {
                        return store.user.page.list[store.user.currentUserIndex + 1]
                    }
                    return null
                }
            },
            actions: {
                setCurrentUser: userAction.setCurrentUser
            }
        },
        route: {
            data: function(transaction){
                var id = transaction.to.params.id
                this.setCurrentUser(id)
            }
        },
        mixins: [userMixin],
        methods: {
            prevUser: function() {
                if(this.prevUserItem != null) this.$router.go('/user/show/' + this.prevUserItem.id)
            },
            nextUser: function() {
                if(this.nextUserItem != null) this.$router.go('/user/show/' + this.nextUserItem.id)
            }
        },
        ready: function(){

        }
    })
})